from django.shortcuts import render
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import generics
from rest_framework.generics import GenericAPIView
from rest_framework.mixins import ListModelMixin, RetrieveModelMixin
from rest_framework.pagination import PageNumberPagination

from app.models import Navbar, Movie, ComingShow
from app.myserializers import NavSerializer, FilmSerializer, ComingFilmSerializer
from rest_framework import serializers
from django.core.serializers import serialize
from django.shortcuts import HttpResponse


class Nav(ListModelMixin, GenericAPIView):
    queryset = Navbar.objects.all()
    serializer_class = NavSerializer

    def get(self, request, *args, **kwargs):
        return self.list(request, *args, **kwargs)


class FilmsList(ListModelMixin, GenericAPIView):
    queryset = Movie.objects.filter(isShow=2)
    serializer_class = FilmSerializer

    def get(self, request, *args, **kwargs):
        return self.list(request, *args, **kwargs)


class MoviesList(APIView):
    def get(self, request):
        film_list = Movie.objects.all()

        serialized_data = serialize("json", film_list)
        return HttpResponse(serialized_data)


class FilmFilter(RetrieveModelMixin, GenericAPIView):
    queryset = Movie.objects.all()
    serializer_class = FilmSerializer

    def get(self, request, *args, **kwargs):
        return self.retrieve(request, *args, **kwargs)


class ComingShowList(ListModelMixin, GenericAPIView):
    queryset = ComingShow.objects.filter(isShow=1)
    serializer_class = ComingFilmSerializer

    def get(self, request, *args, **kwargs):
        return self.list(request, *args, **kwargs)
